package com.rock.common.base;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 
 * @Description:通用返回类 包含返回的状态码，消息，扩展数据
 * @author: hotdog
 * @date: 2018年8月2日 上午11:43:39
 * @Copyright: v1.0
 *
 */
public class BaseResult implements Serializable {

	private static final long serialVersionUID = 1L;
	// 状态码 111-成功 999-失败,其余状态码根据实际情况约定
	private int code;
	// 提示信息
	private String msg;
	// 扩展信息
	private Map<String, Object> extend = new HashMap<String, Object>();

	public static BaseResult success(String mess) {
		BaseResult result = new BaseResult();
		result.setCode(BaseConstants.SUCC);
		result.setMsg(mess);
		return result;
	}

	public static BaseResult fail(String mess) {
		BaseResult result = new BaseResult();
		result.setCode(BaseConstants.FAIL);
		result.setMsg(mess);
		return result;
	}
	
	public static BaseResult others(int code,String mess) {
		BaseResult result = new BaseResult();
		result.setCode(code);
		result.setMsg(mess);
		return result;
	}

	public BaseResult add(String key, Object value) {
		this.getExtend().put(key, value);
		return this;
	}
	
	

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}
	

	public Map<String, Object> getExtend() {
		return extend;
	}

	public void setExtend(Map<String, Object> extend) {
		this.extend = extend;
	}
}
